<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>产品类型</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../script/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../script/base.js"></script>
</head>
<body>
<{if $smarty.get.operation=='add' or $smarty.get.operation=='edit' }>
<div class="container">
<form name="property" id="property" action="module.php?m=product&s=property.php" method="post">
<input name="id" type="hidden" id="id" value="<{$de.id}>">

<div class="type clearfix">
	<span class="cur" data_type="base">基本属性</span>
	<span data_type="extended">扩展属性</span>
	<span data_type="spec">规格</span>
	<span data_type="parameter">详细参数表</span>
</div>
<div class="type_list">
    <div id="base">
    <table class="table3 mb0" id="base">
        <tr>
            <td width="70">类型名称</td>
            <td>
            <input name="pname" id="name" type="text" class="w350" value="<{$de.name}>"><span id="form-error" class="form-error"></span>
            </td>
        </tr>
    </table>
    </div>
    <div class="hidden" id="extended">
     <table class="table4">
        <thead>
        <tr>
        	<td width="120">属性名</td>
        	<td>前台列表页表现类型</td>
        	<td width="220">选择项可选值</td>
        	<td width="30" class="ac">显示</td>
        	<td width="50" class="ac">排序</td>
        	<td width="50" class="ac">操作</td>
        </tr>
        </thead>
        <tbody>
        
        <{foreach item=list key=num from=$de.value}>
        <tr>
			<td>
            <input type="hidden" name="pid[]" value="<{$list.id}>" />
            <input type="text" name="names[]" value="<{$list.field_name}>" />
            </td>
			<td>
            <select name="selects[]">
                <option value="1" <{if $list.display_type==3 && $list.is_search==0}>selected="selected"<{/if}> >下拉不可筛选</option>
                <option value="2" <{if $list.display_type==3 && $list.is_search==1}>selected="selected"<{/if}>>下拉可筛选</option>
                <option value="3" <{if $list.display_type==1}>selected="selected"<{/if}> >输入项</option>
            </select>
            </td>
			<td><a href="javascript:void();" values="<{$num}>" data_type="edit" class="edit">编辑</a><input type="text" class="readonly w150" readonly="readonly" data_type="<{$num}>" name="items[]" value="<{$list.items}>" /></td>
			<td class="ac"><input type="checkbox" <{if $list.statu==1}>checked="checked"<{/if}> value="1" name="status[]" /></td>
            <td>
            <input type="text" class="w50" maxlength="3" name="displayorders[]" value="<{$list.displayorder}>" />
            </td>
            
			<td class="ac"><div><a href="javascript:;" class="deleterow" onclick="deleterows(this)">删除</a></div></td>
        </tr>
        <{/foreach}>
        
        <tr>
            <td colspan="99">
            <ul class="button">
                <li class="button">
                    <a class="a_button" onClick="addrows(this,0)" href="javascript:void(0);">添加一个扩展属性</a>
                </li>
            </ul>
            </td>
        </tr>
        </tbody>
    </table>
    <input type="hidden" name="old_property" value="<{$de.property}>" />
    </div>
    <div class="hidden" id="spec">
    <table class="table4" width="96%">
        <thead>
        <tr>
        	<td>规格</td>
        	<td width="50" class="ac">操作</td>
        </tr>
        </thead>
        <tbody>
        <{foreach item=list key=num from=$de.spec_list}>
       	<tr>
        	<td><{$list.field_name}></td>
            <td class="ac"><div><a href="javascript:;" class="deleterow" onClick="deleterow(this,'<{$list.id}>','list_2')">删除</a></div></td>
        </tr>
        <{/foreach}>
        <tr>
            <td colspan="99">
            <ul class="button">
                <li class="button">
                    <a class="a_button"  id="list_2" values="2" data_type="add" href="javascript:void();">添加规格</a>
                </li>
            </ul>
            </td>
        </tr>
        </tbody>
    </table>
    <input type="hidden" id="hidden_list_2" name="ids[]" value="0,<{if $de.spec}><{$de.spec}>,<{/if}>" />
    <input type="hidden" name="old_ids[]" value="<{$de.spec}>" />
    </div>
    <div class="hidden" id="parameter">
    <table class="table4">
		<tbody>
        	<td>
             <ul class="button">
                <li class="button">
                    <a class="a_button" onClick="addtbody(this)" href="javascript:void(0);">添加参数组</a>
                </li>
            </ul>
            </td>
		</tbody>
    </table>
    <{foreach item=list name=name key=num from=$de.parameter_list}>
    <table class="table4">
        <tbody>
        <tr>
        	<td class="pl20">参数组名称&nbsp;&nbsp;
            <input type="text" class="w150" name="groups[<{$smarty.foreach.name.iteration}>][]" value="<{$num}>" />
            </td>
            <td class="ac" width="60">
            <div><a href="javascript:;" class="deleterow" onClick="deletetbody(this)">删除</a></div>
            </td>
		</tr>
        <{foreach item=slist from=$list}>
        <tr>
            <td class="pl20"><input type="hidden" name="paid[<{$smarty.foreach.name.iteration}>][]" value="<{$slist.id}>" />
            参数名&nbsp;&nbsp;<input type="text" class="w150" name="item_names[<{$smarty.foreach.name.iteration}>][]" value="<{$slist.field_name}>" />
            </td>
            <td class="ac"><div><a href="javascript:;" class="deleterow" onclick="deleterows(this)">删除</a></div></td>
        </tr>
        <{/foreach}>
        <tr>
            <td colspan="99">
                <ul class="button">
                    <li class="button">
                    	<a class="a_button" onClick="addrows(this,1,<{$smarty.foreach.name.iteration}>)" href="javascript:void(0);">添加该组下属性</a>
                    </li>
                </ul>
            </td>
        </tr>
        </tbody>
    </table>
    <{/foreach}>
    <input type="hidden" name="old_parameter" value="<{$de.parameter}>" />
    </div>
</div>


<div class="dialog_button">
<input id="property_button" type="button" value="保存">
<input name="act" type="hidden" id="action" value="<{if !$smarty.get.editid}>save<{else}>edit<{/if}>">
</div>
</form>
<span id="error"></span>
<script>
var i=<{if $de.parameter_list}><{$de.parameter_list|@count}>+1<{else}>1<{/if}>;
function addtbody(obj)
{
	var div = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
	tbody='<table class="table4"><tbody><tr><td class="pl20">参数组名称&nbsp;&nbsp;<input type="text" class="w150" name="group['+i+'][]" value="" /></td><td class="ac" width="60"><div><a href="javascript:;" class="deleterow" onClick="deletetbody(this)">删除</a></div></td></tr><tr><td colspan="99"><ul class="button"><li class="button"><a class="a_button" onClick="addrows(this,1,'+i+')" href="javascript:void(0);">添加该组下属性</a></li></ul></td></tr></tbody></table>';
	i++;
	$(div).append(tbody);
}
function deletetbody(obj) {
	var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
	$(table).remove();
}

$("[data_type='add']").live('click',function(){
								
	var type = $(this).attr('values');
	if(type==2) 
		str="请选择产品规格";

	window.parent.iframe_form("list", str, '<{$config.weburl}>/admin/module.php?m=product&s=list.php&type='+type, 800,600);
	return false;
	
});

$("[data_type='edit']").live('click',function(){
	
	var tr=$(this.parentNode.parentNode);
	var val=tr.find("select").val();
	var id = $(this).attr('values');
	var str = $(this).next().val();

	if(val=='3')
	{
		error('error','对不起，下拉形式下启用！');
		return false;
	}
	window.parent.iframe_form("list", "编辑产品类型扩展属性", '<{$config.weburl}>/admin/module.php?m=product&s=list.php&operation=property&str='+str+'&id='+id, 800,600);
	return false;
	
});

var rowtypedata = [
	[
		['<input type="text" name="name[]" value="" />'], 
		['<select name="select[]"><option value="1">下拉不可筛选</option><option value="2">下拉可筛选</option><option value="3">输入项</option></select>'],
		['<a href="javascript:void();" values="{n}" data_type="edit" class="edit">编辑</a><input type="text" class="readonly w150" readonly="readonly" data_type="{n}" name="item[]" />'],
		['<input type="checkbox" checked="checked" value="1" name="statu[]">','ac'],
		['<input type="text" maxlength="3" class="w50" name="displayorder[]" value="255" />'], 
		['<div><a href="javascript:;" class="deleterow" onClick="deleterows(this)">删除</a></div>','ac'],
		
	],
	[
		['参数名&nbsp;&nbsp;<input type="text" class="w150" name="item_name[{n}][]" value="" />','pl20'], 
		['<div><a href="javascript:;" class="deleterow" onClick="deleterows(this)">删除</a></div>','ac'],
	],
	[
		[''], 
		['<div><a href="javascript:;" class="deleterow" onClick="deleterow(this,{1})">删除</a></div>','ac'],
	
	]
];
var addrowdirects = 0;
var j = 1;
function addrows(obj, type) {
	var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
	if(!addrowdirects) {
		var row = table.insertRow(obj.parentNode.parentNode.parentNode.parentNode.rowIndex);
	} else {
		var row = table.insertRow(obj.parentNode.parentNode.parentNode.parentNode.rowIndex + addrowdirects);
	}
	var typedata = rowtypedata[type];
	for(var i = 0; i <= typedata.length - 1; i++) {
		
		var cell = row.insertCell(i);
		if(typedata[i][1]) {
			cell.className = typedata[i][1];
		}
		var tmp = typedata[i][0];
		if(type==0)
			tmp = tmp.replace(/\{(n)\}/g, function($1) { return j;});
		else
			tmp = tmp.replace(/\{(n)\}/g, function($1, $2) {return addrows.arguments[2];});
		cell.innerHTML = tmp;
	}
	addrowdirects = 0;
	if(type==0) { j++; }
}
function deleterows(obj) {
	var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
	var tr = obj.parentNode.parentNode.parentNode;
	table.deleteRow(tr.rowIndex);
}
var addrowdirect = 0;
var addrowkey = 0;
function addrow(name,num,type) {

	var obj=$('#'+name+'_'+num)[0];	
	var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
	var iframe=window.parent.document.getElementById("iframe_"+name).contentWindow;
	var ul=iframe.document.getElementById("ul");
	var checkbox= $(ul).find("input[type='checkbox']:checked");
	var typedata = rowtypedata[type];
	$.each(checkbox,function(i){
		var value1=$("#hidden_"+name+"_"+num).val();
		var value2=this.value;
		if(value1.indexOf(','+value2+',') <= 0 )
		{
			$("#hidden_"+name+"_"+num).val(value1+value2+',');	
			
			if(!addrowdirect) {
				var row = table.insertRow(obj.parentNode.parentNode.parentNode.parentNode.rowIndex);
			} else {
				var row = table.insertRow(obj.parentNode.parentNode.parentNode.parentNode.rowIndex + 1);
			}
			for(var i = 0; i <= typedata.length - 1; i++) {
		
				var cell = row.insertCell(i);
				
				if(typedata[i][1]) {
					cell.className = typedata[i][1];
				}
				
				if(typedata[i][0])
					var tmp = typedata[i][0];
				else
					var tmp = $(this).next().html();
				
				tmp = tmp.replace(/\{(n)\}/g, function($1) { return value2;});
				tmp = tmp.replace(/\{(\d+)\}/g, function($1, $2) { return value2+',\''+name+'_'+num+'\''; });
				cell.innerHTML = tmp;
			}
			addrowkey ++;
			addrowdirect = 0;
		}
	});
}
function deleterow(obj,id,name) {
	var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
	var tr = obj.parentNode.parentNode.parentNode;
	var value=$("#hidden_"+name).val();
	var pattern = ','+id+',';
	str = value.replace(new RegExp(pattern), ",");
	$("#hidden_"+name).val(str);
	table.deleteRow(tr.rowIndex);
}
$(".type span").click(function () {
	$(this).addClass("cur").siblings().removeClass("cur");
	var name=$(this).attr('data_type');
	$("#"+name).removeClass("hidden").siblings().addClass("hidden");
	
});
$("#property_button").click(function () {
	
	if(!$("#name").val())
	{
		error('error','对不起，类型名称还没有填写');
		return false;
	}
	document.getElementById("property").submit();
	return false;
	
});
</script> 
</div>  
<{else}>
	<div class="container">
        <div class="flow"> 
            <div class="itemtitle">
                <h3>产品类型</h3>
            </div>
        </div>
        <div class="h35"></div>  
         <form action="" method="get">
            <input type="hidden" name="m" value="<{$smarty.get.m}>">
            <input type="hidden" name="s" value="property.php">
            <table class="select_table">
                <tbody>
                    <tr>    
                        <td width="70">类型名称:</td>
                        <td width="250"><input type="text" name="key" class="w250" value="<{$smarty.get.key}>" /></td>
                        <td><input type="image" src="<{$config.weburl}>/image/admin/search.gif" /></td>
                    </tr>
                </tbody>
            </table>
		</form>
		<script type="text/javascript">
        $(function(){
            /* 全选 */
             $('.checkall').click(function(){
                var _self = this;
                $('.checkitem').each(function(){
                    if (!this.disabled)
                    {
                        $(this).attr('checked', _self.checked);
                    }
                });
                $('.checkall').attr('checked', this.checked);
            });	 
        });
        </script>
        <form action="" name="form" id="form" method="post">
        <input type="hidden" name="act" value="op" />
        <table class="table">
            <tbody>
                <tr class="header partition">
                    <th width="10" class="pl20"><input type="checkbox" class="checkall" id="del"></th>
                    <th width="50" class="ac">操作</th>
                    <th>类型名称</th>
                </tr>
                <{foreach item=list from=$de.list}>
                <tr>
                    <td class="pl20"><input type="checkbox" value="<{$list.id}>" class="checkitem" name="chk[]"></td>
                    <td class="ac">
                    <a data_type="edit" href="javascript:void(0);" data-param="{'id':'<{$list.id}>'}"><{$editimg}></a>
					</td>
                    <td><{$list.name}></td>
                </tr>
                <{foreachelse}>
                <tr>
                    <td class="norecord" colspan="99"><i></i><span>暂无符合条件的数据记录</span></td>
                </tr>
                <{/foreach}>
            </tbody>
            <tfoot>    
                <tr>
                    <td colspan="99" class="pl20">
                    <input type="checkbox" class="checkall" id="del">
                    <ul class="button">
                        <li class="button">
                            <a class="a_button" id="del_button" href="javascript:void();">删除</a>
                        </li>
                        <li class="button">
                            <a class="a_button" id="add" href="javascript:void();">添加类型</a>
                        </li>
                    </ul>
                    <div class="page"><{$de.page}></div>
                    </td>
                </tr>
            </tfoot>
        </table>
        </form>
    </div>
	<script>
    $("#del_button").click(function () {
        $("#form")[0].submit();
        return false;
    });
	
    $("#add").live('click',function(){
		window.parent.iframe_form("property", '添加产品类型', '<{$config.weburl}>/admin/module.php?m=product&s=property.php&operation=add', 800, 600);
        return false;
    });
	
	$("[data_type='edit']").live('click',function(){
		var data_str = $(this).attr('data-param');
		eval("data_str = "+data_str);
		window.parent.iframe_form("property", '编辑产品类型', '<{$config.weburl}>/admin/module.php?m=product&s=property.php&operation=edit&editid='+data_str.id, 800, 600);
        return false;
    });
    </script>
</body>
</html>
<{/if}>  